#include "mainscene.h"
#include "config.h"
#include <QIcon>
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>
#include <QObject>
#include <ctime>

Mainscene::Mainscene(QWidget *parent)
    : QWidget(parent)
{
    //调用初始化场景
    initScene();

    //开始按钮
    startButton->setGeometry(GAME_WIDTH/2-100,GAME_HEIGHT/3-25,200,50);
    startButton->setText(QString("开始游戏"));
    startButton->setStyleSheet(
        "font-size:40px;"
        "font-weight:bold;"
        "color:white;"
        "background-color:#4CAF50;"//背景为绿色
        "border-radius:10px");

    //游戏介绍按钮
    introduceButton->setGeometry(GAME_WIDTH/2-100,GAME_HEIGHT*2/3-25,200,50);
    introduceButton->setText(QString("游戏介绍"));
    introduceButton->setStyleSheet(
        "font-size:40px;"
        "font-weight:bold;"
        "color:white;"
        "background-color:#4CAF50;"//背景为绿色
        "border-radius:10px");

    //返回按钮
    returnButton->setGeometry(GAME_WIDTH/2-100,GAME_HEIGHT-150,200,50);
    returnButton->setText(QString("返回"));
    returnButton->hide();
    returnButton->setStyleSheet(
        "font-size:40px;"
        "font-weight:bold;"
        "color:white;"
        "background-color:#4CAF50;"//背景为绿色
        "border-radius:10px");

    //介绍标签
    label_introduce->setStyleSheet("font-size:30px;font-weight:bold;background-color:rgba(173,216,230,100);color:white");
    label_introduce->setGeometry(GAME_WIDTH/4,GAME_HEIGHT/4,GAME_WIDTH/2,GAME_HEIGHT/2);
    label_introduce->setText(QString("操纵那刻夏，躲避怪物攻击\n"
                                     "打败盗火行者，抢回瑟希斯的火种\n"
                                     "拾取瑟希斯的火种，即为胜利\n"
                                     "角色死亡，则失败"));
    label_introduce->setAlignment(Qt::AlignCenter);
    label_introduce->hide();

    //血量显示标签
    label_role_H->setStyleSheet("font-size:24px;font-weight:bold;color:white");
    label_boss_H->setStyleSheet("font-size:24px;font-weight:bold;color:white");
    label_role_H->setGeometry(10,0,200,50);
    label_boss_H->setGeometry(GAME_WIDTH-200,0,200,50);

    //创建游戏结束的标签
    m_gameOverMessageLabel->setAlignment(Qt::AlignCenter);
    m_gameOverMessageLabel->setGeometry(GAME_WIDTH/4,GAME_HEIGHT/3,GAME_WIDTH/2,GAME_HEIGHT/3);
    m_gameOverMessageLabel->hide();//隐藏，结束再显示
    m_gameOverMessageLabel->setStyleSheet(
        "font-size:40px;"
        "font-weight:bold;"
        "color:white;background-color:rgba(0,0,0,180);"//背景为半透明黑色
        "border-radius:10px");

    connect(startButton,&QPushButton::clicked,[=]()
            {
        //启动游戏
        playGame();

        //隐藏开始和介绍按钮
        startButton->hide();
        introduceButton->hide();
            });

    connect(introduceButton,&QPushButton::clicked,[=]()
            {
        label_introduce->show();
        returnButton->show();
        startButton->hide();
        introduceButton->hide();
    });

    connect(returnButton,&QPushButton::clicked,[=]()
            {
        label_introduce->hide();
        returnButton->hide();
        startButton->show();
        introduceButton->show();
    });
}

Mainscene::~Mainscene(){}

void Mainscene::initScene()
{
    //固定尺寸
    setFixedSize(GAME_WIDTH,GAME_HEIGHT);

    //设置标题
    setWindowTitle(GAME_TITLE);

    //加载图标
    setWindowIcon(QIcon(":/image/image/tubiao.png"));

}

void Mainscene::playGame()
{
    //设置定时器
    m_timer.setInterval(GAME_RATE);

    //初始化敌人出现间隔
    m_recorder=0;

    //初始化boss出现时间
    m_Recorder=0;

    //随机数种子
    srand((unsigned int) time(NULL));

    //启动计时器
    m_timer.start();

    //监听定时器发出的信号，每隔GAME_RATE运行一次
    connect(&m_timer,&QTimer::timeout,[=]()
            {
                //更新所有坐标
                updatePosition();

                //绘制到屏幕
                update();//系统函数

                //敌人入场
                enemyToScene();

                //boss出场
                bossToScene();

                //碰撞检测
                collisionDetecction();

                //更新血量标签
                updateLabel();

                //判断游戏进程
                checkGameStatus();
            });
}

//更新坐标
void Mainscene::updatePosition()
{
    //更新地图坐标
    m_map.mapPosition();

    //发射子弹
    shoot();

    //计算并更新所有非空闲子弹的坐标
    for(int i=0;i<BULLET_NUMBER;i++)
    {
        if(m_bullets[i].m_Free==false)
            m_bullets[i].updatePosition();
    }

    //更新非空闲敌人坐标
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        if(m_enemys1[i].m_Free==false)
            m_enemys1[i].updatePosition();
    }

    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        if(m_enemys2[i].m_Free==false)
            m_enemys2[i].updatePosition();
    }

    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        if(m_enemys3[i].m_Free==false)
            m_enemys3[i].updatePosition();
    }

    //更新boss坐标
    if(m_Boss.m_Free==false)
        m_Boss.updatePosition();

    //更新所有非空闲激光（2号敌人的攻击模式）的坐标
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        if(m_enemyattacks2[i].m_Free==false)
            m_enemyattacks2[i].updatePosition();
    }
    //更新所有非空闲光波（3号敌人的攻击模式）的坐标
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        if(m_enemyattacks3[i].m_Free==false)
            m_enemyattacks3[i].updatePosition();
    }
    //更新boss非空闲月刃的坐标
    if(m_Bossattack.m_Free==false)
        m_Bossattack.updatePosition();
    //boss发射月刃
    bossshoot();

    //更新瑟希斯坐标
    if(m_Sxs.m_Free==false)
        m_Sxs.updatePosition();

    //计算爆炸播放图片,依次播放
    for(int i=0;i<BOMB_NUMBER;i++)
    {
        if(m_bombs[i].m_Free==false)
            m_bombs[i].updateInfo();
    }

    for(int i=0;i<BOMB_NUMBER;i++)
    {
        if(m_bossbombs[i].m_Free==false)
            m_bossbombs[i].updateInfo();
    }
}

//绘制
void Mainscene::paintEvent(QPaintEvent *)
{
    QPainter painter(this);

    //绘制地图
    painter.drawPixmap(m_map.m_map1_posX,0,m_map.m_map1);
    painter.drawPixmap(m_map.m_map2_posX,0,m_map.m_map2);

    //绘制角色
    if(m_nkx.m_recorder==0)
        painter.drawPixmap(m_nkx.m_X,m_nkx.m_Y,m_nkx.m_role);
    if(m_nkx.m_recorder>0)
    {
        if(m_nkx.m_recorder>=m_nkx.m_time)
            m_nkx.m_recorder=0;
        if(m_nkx.m_recorder<m_nkx.m_time&&m_nkx.m_recorder>0)
        {
            m_nkx.m_recorder++;
            if(m_nkx.m_recorder/50%2==0)
                painter.drawPixmap(m_nkx.m_X,m_nkx.m_Y,m_nkx.m_role);
        }
    }

    //绘制子弹
    for(int i=0;i<BULLET_NUMBER;i++)
    {
        //如果非空闲，绘制子弹
        if(m_bullets[i].m_Free==false)
            painter.drawPixmap(m_bullets[i].m_X,m_bullets[i].m_Y,m_bullets[i].m_bullet);
    }

    //绘制1号敌人
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果非空闲，绘制敌人
        if(m_enemys1[i].m_Free==false)
            painter.drawPixmap(m_enemys1[i].m_X,m_enemys1[i].m_Y,m_enemys1[i].m_enemy1);
    }
    //绘制2号敌人和它的激光
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果非空闲，绘制2号敌人和它的激光
        if(m_enemys2[i].m_Free==false&&m_enemyattacks2[i].m_Free==false)
        {
            painter.drawPixmap(m_enemys2[i].m_X,m_enemys2[i].m_Y,m_enemys2[i].m_enemy2);
            painter.drawPixmap(m_enemyattacks2[i].m_X,m_enemyattacks2[i].m_Y,m_enemyattacks2[i].m_enemyattack2);
        }
    }
    //绘制3号敌人和它的光波
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果非空闲，绘制3号敌人和光波
        if(m_enemys3[i].m_Free==false)
            painter.drawPixmap(m_enemys3[i].m_X,m_enemys3[i].m_Y,m_enemys3[i].m_enemy3);

        if(m_enemyattacks3[i].m_Free==false)
            painter.drawPixmap(m_enemyattacks3[i].m_X,m_enemyattacks3[i].m_Y,m_enemyattacks3[i].m_enemyattack3);
    }

    //绘制boss和月刃
    if(m_Boss.m_Free==false)
        painter.drawPixmap(m_Boss.m_X,m_Boss.m_Y,m_Boss.m_boss);

    if(m_Bossattack.m_Free==false)
        painter.drawPixmap(m_Bossattack.m_X,m_Bossattack.m_Y,m_Bossattack.m_bossattack);

    //绘制瑟希斯
    if(m_Sxs.m_Free==false)
        painter.drawPixmap(m_Sxs.m_X,m_Sxs.m_Y,m_Sxs.m_sxs);

    //绘制小怪爆炸
    for(int i=0;i<BOMB_NUMBER;i++)
    {
        //如果非空闲，绘制爆炸
        if(m_bombs[i].m_Free==false)
            painter.drawPixmap(m_bombs[i].m_X,m_bombs[i].m_Y,m_bombs[i].m_pixArr[m_bombs[i].m_index]);
    }
    //绘制boss爆炸
    for(int i=0;i<BOMB_NUMBER;i++)
    {
        //如果非空闲，绘制爆炸
        if(m_bossbombs[i].m_Free==false)
            painter.drawPixmap(m_bossbombs[i].m_X,m_bossbombs[i].m_Y,m_bossbombs[i].m_pixArr[m_bossbombs[i].m_index]);
    }
}

//鼠标控制角色
void Mainscene::mouseMoveEvent(QMouseEvent *event)
{
    //角色默认位置是左上角，减去偏移量
    int x=event->x()-m_nkx.m_Rect.width()*0.5;
    int y=event->y()-m_nkx.m_Rect.height()*0.5;

    //边界检测
    if(x<=0)
        x=0;
    if(x>=GAME_WIDTH-m_nkx.m_Rect.width())
        x=GAME_WIDTH-m_nkx.m_Rect.width();
    if(y<=0)
        y=0;
    if(y>=GAME_HEIGHT-m_nkx.m_Rect.height())
        y=GAME_HEIGHT-m_nkx.m_Rect.height();

    //将那刻夏的位置变为鼠标指的位置
    m_nkx.setPosition(x,y);
}

//角色发射子弹
void Mainscene::shoot()
{
    //累加时间间隔
    m_shootrecorder++;
    //未达到设定间隔
    if(m_shootrecorder<BULLET_INTERVAL)
        return;
    //达到设定间隔
    m_shootrecorder=0;//重置
    for(int i=0;i<BULLET_NUMBER;i++)
    {
        //发射空闲子弹
        if(m_bullets[i].m_Free==true)
        {
            m_bullets[i].m_Free=false;
            //设置子弹坐标
            m_bullets[i].m_X=m_nkx.m_X+m_nkx.m_Rect.width()*0.5;
            m_bullets[i].m_Y=m_nkx.m_Y+m_nkx.m_Rect.height()/3;
            break;
        }
    }
}

//随机1个敌人入场
void Mainscene::enemyToScene()
{
    m_recorder++;
    //达到出场间隔，随机生成一个数，生成1个怪物
    if(m_recorder>=ENEMY_INTERVAL)
    {
        m_recorder=0;//重置
        int k=rand()%(3);
        if(k==0)
            enemy1ToScene();
        if(k==1)
            enemy2ToScene();
        if(k==2)
            enemy3ToScene();
    }
}
//敌人1入场
void Mainscene::enemy1ToScene()
{
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //1个空闲敌人出场
        if(m_enemys1[i].m_Free)
        {
            m_enemys1[i].m_Free=false;
            m_enemys1[i].m_health=ENEMY_HEALTH;

            //初始化坐标,Y坐标随机生成
            m_enemys1[i].m_X=GAME_WIDTH;
            m_enemys1[i].m_Y=rand()%(GAME_HEIGHT-m_enemys1[i].m_Rect.height());
            break;
        }
    }
}
//敌人2和它的激光入场
void Mainscene::enemy2ToScene()
{
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //1个空闲2号敌人和它的激光出场
        if(m_enemys2[i].m_Free)
        {
            m_enemys2[i].m_Free=false;
            m_enemyattacks2[i].m_Free=false;
            m_enemys2[i].m_health=ENEMY_HEALTH;

            //初始化坐标,Y坐标随机生成
            m_enemys2[i].m_X=GAME_WIDTH;
            m_enemys2[i].m_Y=rand()%(GAME_HEIGHT-m_enemys2[i].m_Rect.height());
            m_enemyattacks2[i].m_X=m_enemys2[i].m_X-m_enemyattacks2[i].m_Rect.width();
            m_enemyattacks2[i].m_Y=m_enemys2[i].m_Y+m_enemys2[i].m_Rect.height()/3;
            break;
        }
    }
}
//敌人3入场和它的光波
void Mainscene::enemy3ToScene()
{
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //1个空闲敌人出场
        if(m_enemys3[i].m_Free)
        {
            m_enemys3[i].m_Free=false;
            m_enemyattacks3[i].m_Free=false;
            m_enemys3[i].m_health=ENEMY_HEALTH;

            //初始化坐标,Y坐标随机生成
            m_enemys3[i].m_X=GAME_WIDTH;
            m_enemys3[i].m_Y=rand()%(GAME_HEIGHT-m_enemys3[i].m_Rect.height());
            m_enemyattacks3[i].m_X=m_enemys3[i].m_X-m_enemyattacks3[i].m_Rect.width();
            m_enemyattacks3[i].m_Y=m_enemys3[i].m_Y+m_enemys3[i].m_Rect.height()/2;
            break;
        }
    }
}

//boss入场
void Mainscene::bossToScene()
{
    m_Recorder++;
    //达到boss出现的时间，boss变为非空闲,并出场
    if(m_Recorder==BOSS_INTERVAL)
    {
        m_Boss.m_Free=false;
        m_Boss.m_health=BOSS_HEALTH;

        m_Boss.m_X=GAME_WIDTH;
        m_Boss.m_Y=(GAME_HEIGHT-m_Boss.m_boss.height())*0.5;
    }
}
//boss出场后，每隔一段时间发射月刃
void Mainscene::bossshoot()
{
    if(m_Recorder>BOSS_INTERVAL&&m_Boss.m_health>0)
    {
        m_bossshootrecorder++;
        if(m_bossshootrecorder>=m_Bossattack.m_interval)
        {
            m_Bossattack.m_Free=false;
            m_bossshootrecorder=0;//重置
            m_Bossattack.m_X=m_Boss.m_X-m_Bossattack.m_Rect.width();
            m_Bossattack.m_Y=m_Boss.m_Y+m_Boss.m_Rect.height()/3;
        }
    }
}

//碰撞检测，爆炸
void Mainscene::collisionDetecction()
{
    //遍历所有非空闲的子弹
    for(int i=0;i<BULLET_NUMBER;i++)
    {
        //如果是空闲的，执行下一次循环
        if(m_bullets[i].m_Free)
            continue;

        //遍历所有非空闲的1号敌人
        for(int j=0;j<ENEMY_NUMBER;j++)
        {
            //如果是空闲的，执行下一次循环
            if(m_enemys1[j].m_Free)
                continue;

            //如果子弹和敌人相交，则碰撞
            if(m_bullets[i].m_Rect.intersects(m_enemys1[j].m_Rect))//返回值是bool值
            {
                m_bullets[i].m_Free=true;
                m_enemys1[j].m_health--;//敌人血量减一
                if(m_enemys1[j].m_health<=0)
                {
                    m_enemys1[j].m_Free=true;//敌人血量小于或等于0，变为空闲状态

                    //爆炸
                    for(int k=0;k<BOMB_NUMBER;k++)
                    {
                        if(m_bombs[k].m_Free)
                        {
                            //空闲的爆炸播放,变为非空闲
                            m_bombs[k].m_Free=false;
                            //更新爆炸坐标，与敌人坐标相同
                            m_bombs[k].m_X=m_enemys1[j].m_X;
                            m_bombs[k].m_Y=m_enemys1[j].m_Y;
                            break;
                        }
                    }
                }
            }
        }

        //遍历所有非空闲的2号敌人
        for(int j=0;j<ENEMY_NUMBER;j++)
        {
            //如果是空闲的，执行下一次循环
            if(m_enemys2[j].m_Free)
                continue;

            //如果子弹和敌人相交，则碰撞
            if(m_bullets[i].m_Rect.intersects(m_enemys2[j].m_Rect))//返回值是bool值
            {
                m_bullets[i].m_Free=true;
                m_enemys2[j].m_health--;//敌人血量减一
                if(m_enemys2[j].m_health<=0)
                {
                    m_enemys2[j].m_Free=true;//敌人血量小于或等于0，变为空闲状态
                    m_enemyattacks2[j].m_Free=true;

                    //爆炸
                    for(int k=0;k<BOMB_NUMBER;k++)
                    {
                        if(m_bombs[k].m_Free)
                        {
                            //空闲的爆炸播放,变为非空闲
                            m_bombs[k].m_Free=false;
                            //更新爆炸坐标，与敌人坐标相同
                            m_bombs[k].m_X=m_enemys2[j].m_X;
                            m_bombs[k].m_Y=m_enemys2[j].m_Y;
                            break;
                        }
                    }
                }
            }
        }

        //遍历所有非空闲的3号敌人
        for(int j=0;j<ENEMY_NUMBER;j++)
        {
            //如果是空闲的，执行下一次循环
            if(m_enemys3[j].m_Free)
                continue;

            //如果子弹和敌人相交，则碰撞
            if(m_bullets[i].m_Rect.intersects(m_enemys3[j].m_Rect))//返回值是bool值
            {
                m_bullets[i].m_Free=true;
                m_enemys3[j].m_health--;//敌人血量减一
                if(m_enemys3[j].m_health<=0)
                {
                    m_enemys3[j].m_Free=true;//敌人血量小于或等于0，变为空闲状态

                    //爆炸
                    for(int k=0;k<BOMB_NUMBER;k++)
                    {
                        if(m_bombs[k].m_Free)
                        {
                            //空闲的爆炸播放,变为非空闲
                            m_bombs[k].m_Free=false;
                            //更新爆炸坐标，与敌人坐标相同
                            m_bombs[k].m_X=m_enemys3[j].m_X;
                            m_bombs[k].m_Y=m_enemys3[j].m_Y;
                            break;
                        }
                    }
                }
            }
        }

        if(m_Boss.m_Free==false)
        {
            //如果子弹和boss相交，则碰撞
            if(m_bullets[i].m_Rect.intersects(m_Boss.m_Rect))//返回值是bool值
            {
                m_bullets[i].m_Free=true;
                m_Boss.m_health--;//boss血量减一
                if(m_Boss.m_health<=0)
                {
                    //boss死亡，瑟希斯出现
                    m_Boss.m_Free=true;
                    m_Sxs.m_Free=false;
                    m_Sxs.m_X=m_Boss.m_X;
                    m_Sxs.m_Y=m_Boss.m_Y;

                    //爆炸
                    for(int k=0;k<BOMB_NUMBER;k++)
                    {
                        if(m_bossbombs[k].m_Free)
                        {
                            //空闲的爆炸播放,变为非空闲
                            m_bossbombs[k].m_Free=false;
                            //更新爆炸坐标，与敌人坐标相同
                            m_bossbombs[k].m_X=m_Boss.m_X;
                            m_bossbombs[k].m_Y=m_Boss.m_Y;
                            break;
                        }
                    }
                }
            }
        }
    }
    //遍历所有非空闲的敌人
    //1号敌人碰撞
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果是空闲的，执行下一次循环
        if(m_enemys1[i].m_Free)
            continue;

        //如果那刻夏和敌人相交，且不无敌，则碰撞
        if(m_nkx.m_Rect.intersects(m_enemys1[i].m_Rect)&&m_nkx.m_recorder==0)
        {
            m_nkx.m_health--;//血量减一

            //获得无敌时间
            m_nkx.m_recorder=1;
        }
    }
    //2号敌人碰撞
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果是空闲的，执行下一次循环
        if(m_enemys2[i].m_Free)
            continue;

        //如果那刻夏和敌人相交，且不无敌，则碰撞
        if(m_nkx.m_Rect.intersects(m_enemys2[i].m_Rect)&&m_nkx.m_recorder==0)
        {
            m_nkx.m_health--;//血量减一

            //获得无敌时间
            m_nkx.m_recorder=1;
        }
    }
    //3号敌人碰撞
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果是空闲的，执行下一次循环
        if(m_enemys3[i].m_Free)
            continue;

        //如果那刻夏和敌人相交，且不无敌，则碰撞
        if(m_nkx.m_Rect.intersects(m_enemys3[i].m_Rect)&&m_nkx.m_recorder==0)
        {
            m_nkx.m_health--;//血量减一

            //获得无敌时间
            m_nkx.m_recorder=1;
        }
    }
    //boss碰撞
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果是空闲的，执行下一次循环
        if(m_Boss.m_Free)
            continue;

        //如果那刻夏和敌人相交，且不无敌，则碰撞
        if(m_nkx.m_Rect.intersects(m_Boss.m_Rect)&&m_nkx.m_recorder==0)
        {
            m_nkx.m_health--;//血量减一

            //获得无敌时间
            m_nkx.m_recorder=1;
        }
    }
    //2号敌人攻击碰撞
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果是空闲的，执行下一次循环
        if(m_enemyattacks2[i].m_Free)
            continue;

        //如果那刻夏和敌人相交，且不无敌，则碰撞
        if(m_nkx.m_Rect.intersects(m_enemyattacks2[i].m_Rect)&&m_nkx.m_recorder==0)
        {
            m_nkx.m_health--;//血量减一

            //获得无敌时间
            m_nkx.m_recorder=1;
        }
    }
    //3号敌人攻击碰撞
    for(int i=0;i<ENEMY_NUMBER;i++)
    {
        //如果是空闲的，执行下一次循环
        if(m_enemyattacks3[i].m_Free)
            continue;

        //如果那刻夏和敌人相交，且不无敌，则碰撞
        if(m_nkx.m_Rect.intersects(m_enemyattacks3[i].m_Rect)&&m_nkx.m_recorder==0)
        {
            m_nkx.m_health--;//血量减一

            //获得无敌时间
            m_nkx.m_recorder=1;
        }
    }
    //boss月刃碰撞
    if(m_Bossattack.m_Free==false)
    {
        if(m_nkx.m_Rect.intersects(m_Bossattack.m_Rect)&&m_nkx.m_recorder==0)
        {
            m_nkx.m_health--;//血量减一

            //获得无敌时间
            m_nkx.m_recorder=1;
        }
    }
}

void Mainscene::updateLabel()
{
    //游戏结束不更新血量
    if(m_GameOver)
    {
        return;
    }

    label_role_H->setText(QString("血量：%1").arg(m_nkx.m_health));

    if(m_Recorder>BOSS_INTERVAL&&m_Boss.m_health>0)
    {
        label_boss_H->setText(QString("boss血量:%1").arg(m_Boss.m_health));
    }
    else
    {
        if(m_Boss.m_health<=0)//boss死亡
        {
            label_boss_H->setText("Boss被击败");
        }
    }
}

void Mainscene::checkGameStatus()
{
    //如果游戏结束，返回
    if(m_GameOver)
    {
        return;
    }

    //判断那刻夏是否死亡
    if(m_nkx.m_health<=0)
    {
        m_GameOver=true;
        m_GameWon=false;
        m_timer.stop();//停止计时

        m_gameOverMessageLabel->setStyleSheet(
            "font-size: 40px; font-weight: bold; color: red;"
            "background-color: rgba(0, 0, 0, 180); border-radius: 10px;");
        m_gameOverMessageLabel->setText("YOU LOST");
        m_gameOverMessageLabel->show();

        return;//游戏结束
    }

    //boss是否死亡以及那刻夏是否拾取瑟希斯的火种
    if(m_Boss.m_health<=0)
    {
        if(m_nkx.m_Rect.intersects(m_Sxs.m_Rect))
        {
            m_GameOver=true;
            m_GameWon=true;
            m_timer.stop();
            m_Sxs.m_Free=true;

            m_gameOverMessageLabel->setStyleSheet(
                "font-size: 40px; font-weight: bold; color: limegreen; "
                "background-color: rgba(0, 0, 0, 180); border-radius: 10px;");
            m_gameOverMessageLabel->setText("YOU WIN!");
            m_gameOverMessageLabel->show();

            return;//游戏结束
        }
    }
}
